package com.cheng.io;

import java.io.*;

/**
 * JDK7新特性：try-with-resources语法糖用于关闭流，前提是使用的流实现了AutoCloseable接口
 */
public class TryWithResources {

    public static void main(String[] args) {
        try (InputStream in = new FileInputStream("C:\\Users\\ck\\Desktop\\特性.txt");
             OutputStream out = new FileOutputStream("D:\\code\\java-study\\java-study\\io\\resources\\特性.txt")
        ) {
            // 1kb
            byte[] bytes = new byte[1024];
            int readCount = 0;
            while ((readCount = in.read(bytes)) != -1) {
                out.write(bytes, 0, readCount);
            }

            out.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
